package com.packt.webdriver.chapter2;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;

public class MoveByOffsetAndClick2 {
	public static void main(String... args) {
		WebDriver driver = new FirefoxDriver();
		driver.get("file:///C:/Users/gmocanu/Desktop/Selenium%20WebDriver%20Practical%20Guide/8850OS_Code/Chapter%202/HTML/selectable.html");
		WebElement one = driver.findElement(By.name("one"));
		WebElement eleven = driver.findElement(By.name("eleven"));
		WebElement five = driver.findElement(By.name("five"));

		int border = 1;
		int tileWidth = 100;
		int tileHeight = 80;

		Actions builder = new Actions(driver);
		// Click on One
		builder.moveByOffset(one.getLocation().getX() + border,
				one.getLocation().getY() + border).click();
		System.out.println("First element is: " + one.getText());

		builder.build().perform();

		// Click on Eleven.
		builder.moveByOffset(2 * tileWidth + 4 * border,
				2 * tileHeight + 4 * border).click();
		System.out.println("Second element is: " + eleven.getText());
		builder.build().perform();

		// Click on Five
		builder.moveByOffset(-2 * tileWidth - 4 * border,
				-tileHeight - 2 * border).click();
		System.out.println("Third element is: " + five.getText());
		builder.build().perform();
	}
}
